package cn.chenfeifx.core.controls;

import cn.chenfeifx.core.enums.Level;
import javafx.scene.control.Label;
import javafx.stage.Modality;
import javafx.stage.StageStyle;
import org.kordamp.ikonli.javafx.FontIcon;

/**
 * 消息提示组件{@link CFAlert}
 * <p>
 * 打开一个可拖动的Stage：[ {@link StageStyle#TRANSPARENT}，{@link Modality#WINDOW_MODAL} ]，需要提供OwnerWindow，OwnerNode。
 */
public class CFAlert extends CFDialog {

    private final Label contentLabel;

    public CFAlert(String contentText, CFButtonType... buttonTypes) {
        super(null, buttonTypes);
        contentLabel = new Label(contentText);
        initialize();
    }

    private void initialize() {
        contentLabel.setMaxWidth(Double.MAX_VALUE);
        contentLabel.setWrapText(true);
        setContent(contentLabel);
        setLevel(Level.INFO);
        contentLabel.getStyleClass().add("content-label");
        container.setPrefWidth(420); // CFAlert 默认宽度
    }

    public void setLevel(Level level) {
        level.resetStyleClass(container);
        contentLabel.setGraphic(FontIcon.of(level.getIkon()));
    }

    public void setContentText(String contentText) {
        contentLabel.setText(contentText);
    }

}